package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.RecordCoagulation;
import com.water_work_form.entity.RecordDisinfect;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.RecordDisinfectService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * <p>
 * 记录——消毒实验原始记录 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/record-disinfect")
public class RecordDisinfectController {

    @Autowired
    RecordDisinfectService recordDisinfectService;

    /**
     * 记录——消毒实验原始记录 项目新增
     * @param recordDisinfect 新项目
     * @return 返回相应的result， code 0为成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addRecordDisinfect(@RequestBody RecordDisinfect recordDisinfect){
        recordDisinfect.setId(RandomIdUtil.createRandomId());
        recordDisinfectService.save(recordDisinfect);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, recordDisinfect);
    }

    /**
     * 记录——消毒实验原始记录 项目查询
     * @param current 分页 当前页
     * @param status 状态（status）
     * @param size 分页 每页数据量
     * @return 返回相应数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listRecordDisinfect(@RequestParam("current") Integer current, @RequestParam("status") String status, @RequestParam("size") Integer size){
        IPage<RecordDisinfect> page = recordDisinfectService.selectRecordDisinfect(status, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 记录——消毒实验原始记录 项目删除
     * @param id 需删除的项目id
     * @return 返回result，code 0为成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteRecordDisinfect(@RequestParam("id") Long id){
        recordDisinfectService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——消毒实验原始记录  项目更新
     * @param recordDisinfect 更新的项目
     * @return 返回result， code 0为成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateRecordDisinfect(@RequestBody RecordDisinfect recordDisinfect){
        recordDisinfectService.updateById(recordDisinfect);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——消毒实验原始记录 基础表数据查询
     * @param name form表name
     * @param restrictionName29 restriction表name
     * @param restrictionName30 restriction表name
     * @param type device表name
     * @param drugName drug表name
     * @return 返回相应数据
     */
    @ApiOperation("基础表数据查询")
    @GetMapping("/basicList")
    public Result listDisinfect(@RequestParam("name") String name, @RequestParam("restrictionName29") String restrictionName29,
                                @RequestParam("restrictionName30") String restrictionName30, @RequestParam("type") String type,
                                @RequestParam("drugName") String drugName){
        Map<String,Object> map = recordDisinfectService.selectBasicDisinfect(name, restrictionName29, restrictionName30, type, drugName);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, map);
    }

    /**
     * 记录——消毒实验原始记录 数据表导出
     * @param recordDisinfect 需要导出的数据列表
     * @return 返回相应数据
     * @throws IOException 异常
     */
    @ApiOperation("列表导出")
    @PostMapping(value = "/download-word")
    public Result downloadWordRecordDisinfect(@RequestBody RecordDisinfect recordDisinfect) throws IOException  {
        recordDisinfectService.downloadRecordDisinfect(recordDisinfect);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

}

